home *** CD-ROM | disk | FTP | other *** search
/ The Best of MacTutor - S…e Code for Volumes 1 to 5 / The Best of MacTutor - Source Code for Volume 1-5 (Wayzata Technology)(6031)(1990).bin / Source Code / #25 (Oct 87) / cdev source / AF Source next >
Text File  |  1987-08-13  |  3KB  |  145 lines

  1. { AppFont    -    Application Font Control by Steve Sheets                }
  2. {                Control Panel Proc to change the Application Font        }
  3.  
  4. UNIT AFunit;
  5.  
  6. INTERFACE
  7.  
  8.     FUNCTION Main (message, item, numitems, CPanel : integer;
  9.                                     theEvent : EventRecord;
  10.                                     cdevStorage : longint;
  11.                                     CPDialog : DialogPtr) : longint;
  12.  
  13. IMPLEMENTATION
  14.  
  15. {    Given the DialogPtr to the Control Panel, and the number of items in the}
  16. {        original Control Panel DITL and the Number of the Font Button to be}
  17. {        selected, selects that Font Button and unselects all the other Buttons.}
  18.     PROCEDURE DoHit (N, X : integer;
  19.                                     CP : DialogPtr);
  20.         VAR
  21.             count : integer;
  22.             myT : integer;
  23.             myH : handle;
  24.             myR : rect;
  25.     BEGIN
  26.         FOR count := X + 1 TO X + 16 DO
  27.             BEGIN
  28.                 GetDItem(CP, count, myT, myH, MyR);
  29.                 IF count = N THEN
  30.                     SetCtlValue(Controlhandle(myH), 1)
  31.                 ELSE
  32.                     SetCtlValue(Controlhandle(myH), 0);
  33.             END;
  34.     END;
  35.  
  36. {    First finds the current Application Font ID number, converts that ID number}
  37. {        into corresponding Font Button number and returns that number.}
  38.     FUNCTION CurNum : integer;
  39.         VAR
  40.             SP : SysPPtr;
  41.             V : integer;
  42.     BEGIN
  43.         SP := GetSysPPtr;
  44.         V := SP^.Font + 1;
  45.  
  46.         CASE V OF
  47.             0 : 
  48.                 CurNum := 1;
  49.             2, 3, 4, 5, 6, 7, 8, 9 : 
  50.                 CurNum := V;
  51.             11, 12 : 
  52.                 CurNum := V - 1;
  53.             20, 21, 22, 23, 24 : 
  54.                 CurNum := V - 8;
  55.             OTHERWISE
  56.                 CurNum := 0;
  57.         END;
  58.     END;
  59.  
  60. {    Given the Font Button number, converts it into the Application Font ID number,}
  61. {        then sets the current Application Font to that number.}
  62.     PROCEDURE SetNum (N : integer);
  63.         VAR
  64.             SP : SysPPtr;
  65.             E : OSErr;
  66.             V : integer;
  67.     BEGIN
  68.         CASE N OF
  69.             1 : 
  70.                 V := 0;
  71.             2, 3, 4, 5, 6, 7, 8, 9 : 
  72.                 V := N;
  73.             10, 11 : 
  74.                 V := N + 1;
  75.             12, 13, 14, 15, 16 : 
  76.                 V := N + 8;
  77.             OTHERWISE
  78.                 V := Geneva;
  79.         END;
  80.         SP := GetSysPPtr;
  81.         SP^.Font := V - 1;
  82.         E := WriteParam;
  83.     END;
  84.  
  85. {    For all the Font Buttons, checks to see if that Font is installed in the system.}
  86. {        If it is not installed, unhilites the corresponding button so it can not be}
  87. {        selected.}
  88.     PROCEDURE ZapFonts (CP : DialogPtr;
  89.                                     N : integer);
  90.         VAR
  91.             count, F : integer;
  92.             S : str255;
  93.             myT : integer;
  94.             myH : handle;
  95.             myR : rect;
  96.     BEGIN
  97.         FOR count := 1 TO 16 DO
  98.             BEGIN
  99.                 CASE count OF
  100.                     1 : 
  101.                         F := 0;
  102.                     2, 3, 4, 5, 6, 7, 8, 9 : 
  103.                         F := count;
  104.                     10, 11 : 
  105.                         F := count + 1;
  106.                     12, 13, 14, 15, 16 : 
  107.                         F := count + 8;
  108.                     OTHERWISE
  109.                 END;
  110.                 GetFontName(F, S);
  111.                 GetDItem(CP, N + count, myT, myH, MyR);
  112.                 IF S = '' THEN
  113.                     HiliteControl(ControlHandle(myH), 255)
  114.                 ELSE
  115.                     HiliteControl(ControlHandle(myH), 0);
  116.             END;
  117.     END;
  118.  
  119. {    cdev Main Function.    Handles InitDev call (Zaps all the unistalled Font Buttons}
  120. {        and selects the current Font Button) and the HitDev calls (selects the}
  121. {        pressed Font Buttons and sets the Application Font to that Font.}
  122.     FUNCTION Main;
  123.         VAR
  124.             Val : longint;
  125.     BEGIN
  126.         IF (cdevStorage <> 0) AND (cdevStorage <> 1) AND (cdevStorage <> -1) THEN
  127.             BEGIN
  128.                 CASE Message OF
  129.                     0 :                 {InitDev}
  130.                         BEGIN
  131.                             ZapFonts(CPDialog, numitems);
  132.                             DoHit(CurNum + numitems, numitems, CPDialog);
  133.                         END;
  134.                     1 :                  {HitDev}
  135.                         BEGIN
  136.                             DoHit(item, numitems, CPDialog);
  137.                             SetNum(item - numitems);
  138.                         END;
  139.                     OTHERWISE
  140.                 END;
  141.             END;
  142.         Main := cdevStorage;
  143.     END;
  144.  
  145. END.